package com.gxa.employment.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description: 返回给前端的统一的封装类型
 * @Author: 
 * @DateTime: 2025/1/17 9:45
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    /**
     * 无数据成功返回
     * @param data
     * @return
     * @param <T>
     */
    public static <T> Result<T> success(T data) {
        return new Result<T>(200, "success", data);
    }

    /**
     * 有数据成功返回
     * @return
     * @param <T>
     */
    public static <T> Result<T> success() {
        return new Result<T>(200, "success", null);
    }

    /**
     * 失败返回
     * @return
     * @param <T>
     */
    public static <T> Result<T> error() {
        return new Result<T>(500, "系统开小差了,请稍后再试", null);
    }

    /**
     * 业务异常判断
     * @param code
     * @param msg
     * @return
     * @param <T>
     */
    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<T>(code, msg, null);
    }
}
